﻿using Apps.BLL.Core;
using Apps.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.BLL.PUB
{
   public partial class PUB_EQUIPMENTBLL
    {

        public override bool Delete(ref ValidationErrors errors, object id)
        {
            try
            {
                var item = m_Rep.Context.PUB_EQUIPMENT.Where(m => m.EQUIPMENT_ID == id.ToString()).FirstOrDefault();
                if (item != null)
                {
                    m_Rep.Context.DEV_CHECK.RemoveRange(item.DEV_CHECK);
                    m_Rep.Context.DEV_COME.RemoveRange(item.DEV_COME);
                    m_Rep.Context.DEV_EXPERIENCE.RemoveRange(item.DEV_EXPERIENCE);
                    m_Rep.Context.DEV_GREASE.RemoveRange(item.DEV_GREASE);
                    m_Rep.Context.DEV_MEMORABILIA.RemoveRange(item.DEV_MEMORABILIA);
                    m_Rep.Context.DEV_SPARE.RemoveRange(item.DEV_SPARE);
                    m_Rep.Context.DEV_TECHNICAL.RemoveRange(item.DEV_TECHNICAL);
                    m_Rep.Context.PUB_EQUIPMENT.Remove(item);
                    m_Rep.Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
            return true;
        }
    }
}
